/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.J2SE.Thread;

/**
 *
 * @author kylin
 */
public class TestThreadYield2 extends Thread {
    public TestThreadYield2(String name){
        super(name);
    }
    public void run(){
        for(int i=0;i<50;i++){
            System.out.println(getName()+" "+i);
            if(i==20){
                Thread.yield();
            }
        }
    }
    public static void main(String args[]) throws Exception{
        //启动两个并发线程
        TestThreadYield2 yt1=new TestThreadYield2("高级");
        //将yt1线程设置成最高优先级
        yt1.setPriority(Thread.MAX_PRIORITY);
        yt1.start();
        TestThreadYield2 yt2=new TestThreadYield2("低级");
        //将yt2线程设置成最低优先级
        yt2.setPriority(Thread.MIN_PRIORITY);
        yt2.start();
    }
}
